package wojtek.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JTextField;
import javax.swing.JButton;

public class AutoGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txtMarka;
	private JTextField txtModel;
	private JTextField txtRokprodukcji;
	private JTextField txtPojemnosc;
Auto daneAuto;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Auto auto1 = new Auto();
					AutoGUI frame = new AutoGUI(auto1);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public AutoGUI(Auto auto) {
		this.daneAuto = auto;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblMarka = new JLabel("Marka");
		contentPane.add(lblMarka, "4, 2, right, default");
		
		txtMarka = new JTextField();
		txtMarka.setText(daneAuto.getMarka());
		contentPane.add(txtMarka, "6, 2, fill, default");
		txtMarka.setColumns(10);
		
		JLabel lblModel = new JLabel("Model");
		contentPane.add(lblModel, "4, 4, right, default");
		
		txtModel = new JTextField();
		txtModel.setText(daneAuto.getModel());
		contentPane.add(txtModel, "6, 4, fill, default");
		txtModel.setColumns(10);
		
		JLabel lblRokProdukcji = new JLabel("Rok produkcji");
		contentPane.add(lblRokProdukcji, "4, 6, right, default");
		
		txtRokprodukcji = new JTextField();
		txtRokprodukcji.setText(Integer.toString(daneAuto.getRokProdukcji()));
		contentPane.add(txtRokprodukcji, "6, 6, fill, default");
		txtRokprodukcji.setColumns(10);
		
		JLabel lblPojemnosc = new JLabel("Pojemnosc");
		contentPane.add(lblPojemnosc, "4, 8, right, default");
		
		txtPojemnosc = new JTextField();
		txtPojemnosc.setText(Double.toString(daneAuto.getPojemnosc()));
		contentPane.add(txtPojemnosc, "6, 8, fill, default");
		txtPojemnosc.setColumns(10);
		
		JCheckBox chckbxSprawnosc = new JCheckBox("Sprawnosc");
		contentPane.add(chckbxSprawnosc, "4, 10");
		chckbxSprawnosc.setSelected(daneAuto.isSprawne());
		
		JButton btnZapisz = new JButton("Zapisz");
		contentPane.add(btnZapisz, "6, 12");
		btnZapisz.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				zapiszDane();
				wypis();

			}
		});
		
		
	}

	public void zapiszDane(){
		daneAuto.setMarka(txtMarka.getText());
		daneAuto.setModel(txtModel.getText());
		daneAuto.setRokProdukcji(Integer.parseInt(txtRokprodukcji.getText()));
		daneAuto.setPojemnosc(Double.parseDouble(txtPojemnosc.getText()));
		//daneAuto.setSprawne(chckbxSprawnosc.isSelected());
	};
	
	public void wypis(){
		System.out.println(daneAuto.getMarka());
	}
}
